// Copyright 2023 Srhino Co., Ltd. All rights reserved.

package main

import (
	"context"
	ifacev1 "git.ouryun.cn/lzj1/grpc-bidirectional-stream/pkg/interfaces/v1"
	"git.ouryun.cn/lzj1/grpc-bidirectional-stream/pkg/services/v1"
	"ouryun.com/web-demo/client/pkg/webserver"
	"ouryun.com/web-demo/utils"
)

func main() {
	var server ifacev1.GrpcServer

	app := webserver.NewServer("127.0.0.1", 9080, server)
	wait := make(chan struct{})
	//md := metadata.Pairs("client-id", "123")
	//ctx := metadata.NewOutgoingContext(context.Background(), md)
	ctx := context.WithValue(context.Background(), "client-id", 123)
	server = v1.NewGrpcClient("127.0.0.1:10086", ctx, app.Callback)
	app.SetGs(server)
	go func() {
		err := server.Start()
		if err != nil {
			utils.Logger.Error(err)
		}
	}()
	// 启动web服务

	err := app.Start()
	if err != nil {
		utils.Logger.Error(err)
	}

	<-wait
}

//func Callback(message *apis.StreamMessage) {
//	request, err := server.Request(message, nil, apis.StreamMessage_RESPONSE_TYPE)
//	if err != nil {
//		return
//	}
//	utils.Logger.Infof("收到响应消息3%v", request)
//}
